package Controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.SQLException;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

import Entity.Transfer;
import Model.MakeNewModel;
import Model.RequestTranferEmpModel;
import View.MakeNewView;
import View.RequestTransferEmpView;

public class RequestTransferEmpController {
	private JInternalFrame iframe;
	private RequestTransferEmpView view;
	private RequestTranferEmpModel model;

	public RequestTransferEmpController() {
		iframe = new JInternalFrame();
		view = new RequestTransferEmpView();
		model = new RequestTranferEmpModel();
		doAction();
		iframe.add(view);
		iframe.setSize(700, 450);
		iframe.setVisible(true);
	}
	public JInternalFrame getFrame(){
		return iframe;
	}
	private void doAction() {
		// TODO Auto-generated method stub
		doLoadComboBox();
		doMake();
		doExit();
	}

	private void doLoadComboBox() {
		// TODO Auto-generated method stub
		try {
			view.loadLocation();
			view.loadProject();
			view.loadDepartment();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private void doExit() {
		// TODO Auto-generated method stub
		view.doExit(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				iframe.dispose();
			}
		});
	}

	private void doMake() {
		// TODO Auto-generated method stub
		view.doMake(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				Transfer transfer = new Transfer(view.getEmpNumber(), view
						.getEmpName(), view.getFromLocation(), view
						.getToLocation(), view.getFromProject(), view
						.getToProject(), view.getFromDepartment(), view
						.getToDepartment(),0);
						//,view.getJoinDate(),view.getRelieve());
				try {
					model.makeNewTransfer(transfer);
					JOptionPane.showMessageDialog(iframe, "Bạn vừa tạo mới 1 transfer", "Thông báo", 0);
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ClassNotFoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}
}
